

#include "all.h"
#include "globals.h"
#include "DisplayString.h"
#include "handleEvents.h"
#include "processSurface.h"

void youLostMenu(const char *str) {
    SDL_Surface *screenSave = SDL_CreateRGBSurface(SDL_HWSURFACE, screenSurface->w, screenSurface->h, 32, bmask, gmask, rmask, amask);
    SDL_BlitSurface(screenSurface, NULL, screenSave, NULL);


    int len = strlen(str);
    SDL_Surface *temp = SDL_CreateRGBSurface(SDL_HWSURFACE, len*LARGE_FONT_SPACING, 48, 32, bmask, gmask, rmask, amask);


    int x=(SCREEN_WIDTH-len*LARGE_FONT_SPACING)/2;
    int y=(SCREEN_HEIGHT-48)/2;

    SDL_Rect srcRect;
    srcRect.x = x;
    srcRect.y = y;
    srcRect.w = len*LARGE_FONT_SPACING;
    srcRect.h = 48;



    int n=100;

    int mouseX;
    bool wait=true;
    quit = false;
    while (wait) {
        handleEvents();
        SDL_PumpEvents();
        Uint8 *keystates = SDL_GetKeyState( NULL );
		if(quit || (keystates[ SDLK_KP_ENTER ] ||  keystates[ SDLK_RETURN ] || keystates[SDLK_SPACE] || SDL_GetMouseState(&mouseX,&mouseX)&SDL_BUTTON(1)))
		wait = false;

        if (n) {
            n--;
            processSurface();
            SDL_BlitSurface(screenSurface, &srcRect, temp, NULL);
            DisplayString::drawString(str, x, y);
            SDL_Flip( screenSurface);
            SDL_BlitSurface(temp, NULL, screenSurface, &srcRect);
        }
        SDL_Delay(40);
    }
    SDL_FreeSurface(temp);
    SDL_BlitSurface(screenSave, NULL, screenSurface, NULL);
    SDL_FreeSurface(screenSave);


    wait = true;

    while (wait) {
        quit = false;
        handleEvents();
        SDL_PumpEvents();
        Uint8 *keystates = SDL_GetKeyState( NULL );
		if(quit==false && !(keystates[ SDLK_KP_ENTER ] ||  keystates[ SDLK_RETURN ] || keystates[SDLK_SPACE] || SDL_GetMouseState(&mouseX,&mouseX)&SDL_BUTTON(1)))
		wait = false;

        SDL_Delay(50);
    }


//    waitForKeyRelease();
}
